package cn.tedu.plus.sort;

import java.util.Arrays;
import java.util.Random;

public class BubbleSort {
    public static void main(String[] args) {
        Random random = new Random();
        int[] array = new int[1000];
        for (int i = 0; i < 1000; i++) {
            array[i]=random.nextInt(100);
        }
        System.out.println(Arrays.toString(array));

        Long countNum = 0L;
        Long swapNum =0L;
        Long startTime = System.currentTimeMillis();

        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array.length-1-i; j++) {
                countNum++;
                if(array[j]<array[j+1]){
                    swapNum++;
                    int temp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = temp;
                }
            }
        }

        Long endTime = System.currentTimeMillis();

        System.out.println("对比次数："+countNum);
        System.out.println("换位次数："+swapNum);
        System.out.println("耗时："+(endTime-startTime)+"毫秒");
        System.out.println(Arrays.toString(array));



    }
}
